package com.zerui.manager.web.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum DeviceFromEnum {

    FROM_IOT(1, "IoT"),
    FROM_ICC(2, "ICC");

    private final int code;

    private final String name;

    DeviceFromEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }


    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static List<Map<String, Object>> getOptions() {
        List<Map<String, Object>> options = new ArrayList<>();
        DeviceFromEnum[] enums = DeviceFromEnum.values();
        for (DeviceFromEnum item : enums) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode());
            map.put("name", item.getName());
            options.add(map);
        }
        return options;
    }

    public static String getLabel(int from) {
        DeviceFromEnum[] enums = DeviceFromEnum.values();
        for (DeviceFromEnum item : enums) {
            if (from == item.getCode())
                return item.getName();
        }
        return "未知";
    }
}
